package com.huawei.esdk.tp.common.local.site;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
import javax.xml.ws.Holder;
import javax.xml.ws.soap.SOAPFaultException;
import com.huawei.esdk.tp.common.local.MyFaultException;
import com.huawei.esdk.tp.common.local.bean.CameraControl;
import com.huawei.esdk.tp.common.local.bean.SiteInfo;
import com.huawei.esdk.tp.common.local.impl.autogen.SiteFreeBusyStates;
import com.huawei.esdk.tp.common.local.impl.autogen.SitesStatusMap;
import com.huawei.esdk.tp.common.local.impl.autogen.TPCommonSiteCtr;
import com.huawei.esdk.tp.common.local.impl.autogen.TPCommonSiteMgr;

public class SiteImpl implements TPCommonSiteCtr, TPCommonSiteMgr {

	public static int querySiteByNameResult = 0;
	public static int querySitesFreeBusyResult = 0;
	public static int querySiteByURIResult = 0;
	public static int queryAllSitesResult = 0;
	public static int querySiteFreeBusyResult = 0;
	public static int connectSitesResult = 0;
	public static int micMuteSitesResult = 0;
	public static int ctrlAuxStreamResult = 0;
	public static int ctrlCameraResult = 0;
	public static int disconnectSitesResult = 0;
	public static int spkQuietSitesResult = 0;
	
	public static boolean throwException = false;
	public static int exceptionCode = 0; 
	
	private SOAPFaultException getSOAPFaultException(){
		SOAPFaultException se = null;
		try {
			SOAPFault fault = new MyFaultException();;
			fault.setFaultCode(String.valueOf(exceptionCode));
			se = new SOAPFaultException(fault);
		} catch (SOAPException e) {
			e.printStackTrace();
		}
		return se;
	}
	@Override
	public void querySiteByName(String siteName, Holder<Integer> resultCode,
			Holder<List<SiteInfo>> sitesInfo) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = querySiteByNameResult;
		SiteInfo info = new SiteInfo();
		info.setName("西门吹雪");
		info.setUri("01010086");
		List<SiteInfo> list = new ArrayList<SiteInfo>();
		list.add(info);
		sitesInfo.value = (list);
	}

	@Override
	public void querySitesFreeBusy(List<String> siteUris, Integer timeRange,
			Holder<Integer> resultCode,
			Holder<List<SitesStatusMap>> sitesFreeBusyState) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = querySitesFreeBusyResult;
		sitesFreeBusyState.value = new ArrayList<SitesStatusMap>();

	}

	@Override
	public void querySiteByURI(String siteUri, Holder<Integer> resultCode,
			Holder<SiteInfo> siteInfo) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = querySiteByURIResult;
		SiteInfo info = new SiteInfo();
		info.setName("西门吹雪");
		siteInfo.value = info;
	}

	@Override
	public void queryAllSites(Holder<Integer> resultCode,
			Holder<List<SiteInfo>> sitesInfo) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = queryAllSitesResult;
		sitesInfo.value = new ArrayList<SiteInfo>();
	}

	@Override
	public void querySiteFreeBusy(String siteUri, Holder<Integer> resultCode,
			Holder<Integer> state) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = querySiteFreeBusyResult;
		state.value = 0;
	}

	@Override
	public Integer connectSites(String confId, List<String> siteUris) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return connectSitesResult;
	}

	@Override
	public Integer micMuteSites(String confId, List<String> siteUris,
			Boolean isMute) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return micMuteSitesResult;
	}

	@Override
	public Integer ctrlAuxStream(String siteUri, Integer controlCode) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return ctrlAuxStreamResult;
	}

	@Override
	public Integer ctrlCamera(String siteUri, CameraControl cameraControl) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return ctrlCameraResult;
	}

	@Override
	public Integer disconnectSites(String confId, List<String> siteUris) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return disconnectSitesResult;
	}

	@Override
	public Integer spkQuietSites(String confId, List<String> siteUris,
			Boolean isQuiet) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return spkQuietSitesResult;
	}

	@Override
	public void querySiteStatus(
    List<String> siteUris, 
    Date beginTime,
    Integer timeRange,
    Holder<Integer> resultCode,
    Holder<List<SiteFreeBusyStates>> siteFreeBusyStates)
    {

        
    }

}
